import Vue from 'vue'
import Router from 'vue-router'
let login = ()=>import('@/components/login') //登录页面
let home = ()=>import('@/components/home')
let user = ()=>import('@/views/User/user')//用户管理
let rights = ()=>import('@/views/Rights/rights') //权限管理
let roles = ()=>import('@/views/Roles/roles')//角色管理
let categories = ()=>import('@/views/Categories/categories')//商品分类\
let goods = ()=>import('@/views/Goods/goods') //商品列表
let add = ()=>import('@/views/Goods/base/add')//添加商品
let order = ()=> import('@/views/Order/order')//订单管理
let report = ()=>import('@/views/Reports/reports')//数据报表
let params = ()=>import('@/views/Params/params')//分类参数

Vue.use(Router)

const router = new Router({
  mode:"history",
  routes: [
          {path:"/",redirect:"/login"},
         {path:"/login",name:'login',component:login},
         {
           path:"/home",
           name:'home',
           component:home,
           redirect:"home/users",
           children:[
             
             {path:'users',component:user,name:'user'},
             {path:'rights',component:rights,name:'rights'},
             {path:'roles',component:roles,name:'roles'},
              {path:'categories',component:categories,name:'categories'},
              {path:'goods',component:goods,name:'goods'},
              {path:'goods/add',component:add,name:'add'},
              {path:'params',component:params,name:'params'},
              {path:'orders',component:order,name:'order'},
              {path:'reports',component:report,name:'report'}
           ],
           
          } 
  ]
})

router.beforeEach((to,from,next)=>{
  if(to.path == '/login') return next()
  const token = window.sessionStorage.getItem('token');
  if(!token) return next("/login")
  window.sessionStorage.setItem('activePath',to.path)
  next();
 
})

export default router

